/**
 * hack处理
 */
(function(){
	/**
	 * 对象hack 及扩展
	 */
	function hackObject(){
		if (!Object.keys) {
			Object.keys = (function () {
				var hasOwnProperty = Object.prototype.hasOwnProperty,
					hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
					dontEnums = [
						'toString',
						'toLocaleString',
						'valueOf',
						'hasOwnProperty',
						'isPrototypeOf',
						'propertyIsEnumerable',
						'constructor'
					],
					dontEnumsLength = dontEnums.length;

				return function (obj) {
					if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object');

					var result = [];

					for (var prop in obj) {
						if (hasOwnProperty.call(obj, prop)) result.push(prop);
					}

					if (hasDontEnumBug) {
						for (var i=0; i < dontEnumsLength; i++) {
							if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
						}
					}
					return result;
				}
			})()
		};
		/**
		 * 显示对象属性
		 * @param obj
		 * @returns {string}
		 */
		if(!Object.showObjProperty){
			Object.showObjProperty = function(obj) {
				var strPropertyList = '<br/>';
				var iPropertyCount = 0;
				var j = 0;
				for (var key in obj) {
					if (Object.prototype.toString.call(obj[key]) === "[object Function]") {
						strPropertyList = strPropertyList + '方法:' + key /*+'='+obj[key]+'&nbsp;&nbsp;&nbsp;形参数('*/ + '(' + obj[key].length/*+':'+strVars*/ + ') ### ';
					} else {
						strPropertyList = strPropertyList + '属性:' + key + '=' + obj[key] + ' ### ';
					}
					if (j % 6 == 5) {
						strPropertyList = strPropertyList + "<br/>"
					}
					j++;
				}
				return strPropertyList;
			}
		}
	}
	/**
	 * 字符串hack 及扩展
	 */
	function hackString() {
		var sp = String.prototype;
		if (!sp)return;

		sp.substr = sp.substr || function (start, length) {
			len = this.length;
			length = length || len;
			if (length > len)length = len;
			if (start < 0)start = 0;
			var r = '';
			for (var i = start; i < length; i++) {
				r += this[i];
			}
			return r;
		};
	};
	/**
	 * 数组hack
	 */
	function hackArray() {
		var ap = Array.prototype;
		if (!ap)return;

		ap.push = ap.push || function (item) {
			if (!item)return;
			if (!this.length)this.length = 0;
			this[this.length] = item;
		}
		//打乱数组顺序
		ap.shuffle = ap.shuffle  || function(){
			var i,tmp,l = this.length;
			while(l){
				i = Math.floor(Math.random()*l--);
				tmp = this[l];
				this[l] = arr[i];
				this[i] = tmp;
			}
			return this
		};
		//数组去重
		ap.unique = function(){
			var result = [];
			var i= 0,l=this.length;
			for(i;i<l;i++){
				if(result.indexOf(this[i]) == -1){
					result.push(this[i]);
				}
			}
			return result;
		};
		//随机获取一个
		ap.randomOne = function () {
			return this[Math.floor(Math.random() * this.length)];
		}
		ap.each = function(fn){
			for (var i = 0, len = this.length; i < len; i++) { fn(this[i], i); }
		}
	};
	/**
	 * 数学操作hack及货站
	 */
	function hackMath(){
		var mp = Math;
		var fnRandom = Math.random;
		/**
		 * 根据给定范围获取随机数
		 * @param min
		 * @param max
		 * @returns {number}
		 */
		mp.random = function(min,max) {
			if(isNaN(max)){
				min = 0;
				max = min || 1;
			}
			return  min+fnRandom() * (max-min);
		}
		//保留s位小数点,多余的去掉,没有的就补上0
		mp.toFixed = function(num,s){
			var reg = '/([0-9]+.[0-9]{'+s+'})[0-9]*/';
			var num=parseInt(num*Math.pow(10,s));
			num=(num+0.1)/Math.pow(10,s);
			var strNew=num.toString().replace(eval(reg),"$1");
			return -1 != strNew.indexOf(".") ? parseFloat(strNew) : parseInt(strNew);
		}
	}
	/**可以屏蔽机顶盒自身的浏览器缺省行为，如有元素超过边界会自动滚动的行为*/
	try {
		Navigation.disableDefaultNavigation();
	} catch (e) {
	} 
	hackObject();
	hackString();
	hackArray();
	hackMath()
})();